package cn.edu.lcu.cs.designpattern.observer.plain;

import java.util.Observable;

/**
 * 使用Java内置的Observable类模拟被观赛对象--草原。
 * 但是java.util.Observable从JDK9开始被淘汰了。
 */
public class Plain extends Observable {
    private Season season;

    public Season getSeason() {
        return season;
    }

    public void setSeason(Season season) {
        this.season = season;
    }

    public Plain() {
        this.season = Season.DRY;
    }

    public Plain(Season season) {
        this.season = season;
    }

    /**
     * 改变季节
     */
    public void change() {
        if (season == Season.DRY) {
            season = Season.RAINY;
        } else {
            season = Season.DRY;
        }
        setChanged(); // 设置修改标志为真
//        notifyObservers(); // 通知所有的观察者，并且清除修改标志
        notifyObservers(season); // 通知所有的观察者，并且清除修改标志；通知时可以传递参数
    }

    /**
     * 旱季，雨季
     */
    public enum Season {DRY, RAINY}
}
